package com.cskaoyan.controller.promote;

import com.cskaoyan.bean.BaseRespVo;

import com.cskaoyan.bean.promote.Advertising;
import com.cskaoyan.bean.promote.base.PromotePageData;
import com.cskaoyan.bean.promote.base.PromoteParam;
import com.cskaoyan.bean.promote.bo.AdvertisingSearchBO;
import com.cskaoyan.bean.promote.exception.AddAdvertisingException;
import com.cskaoyan.bean.promote.exception.DeleteAdvertisingException;
import com.cskaoyan.bean.promote.exception.UpdateAdvertisingException;
import com.cskaoyan.service.promote.AdvertisingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author liXiaoFei
 * @date 2021/10/18 17:06
 */
@RestController
@RequestMapping("admin/ad")
@Transactional
public class AdvertisingController {

    @Autowired
    AdvertisingService advertisingService;

    @RequiresPermissions("admin:ad:list")
    @GetMapping("list")
    public BaseRespVo list(PromoteParam promoteParam,AdvertisingSearchBO advertisingSearchBO){
        PromotePageData data = advertisingService.queryAdvertising(promoteParam,advertisingSearchBO);
        return BaseRespVo.ok(data);
    }
    @RequiresPermissions("admin:ad:create")
    @PostMapping("create")
    public BaseRespVo create(@RequestBody Advertising advertising) throws AddAdvertisingException {

        Advertising advertisingVO = advertisingService.addAdvertising(advertising);
        return BaseRespVo.ok(advertisingVO);
    }
    @RequiresPermissions("admin:ad:update")
    @PostMapping("update")
    public BaseRespVo update(@RequestBody Advertising advertising) throws UpdateAdvertisingException {
        Advertising advertisingVO = advertisingService.updateAdvertising(advertising);
        return BaseRespVo.ok(advertisingVO);
    }
    @RequiresPermissions("admin:ad:delete")
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Advertising advertising) throws DeleteAdvertisingException {
        advertisingService.deleteAdvertising(advertising);
        return BaseRespVo.ok();
    }

}
